<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="../../layui/css/layui.css" media="all">
<title>生产计划增加</title>
</head>

<body>

	<fieldset class="layui-elem-field layui-field-title"
		style="margin-top: 20px;">
		<legend>生产计划增加列表</legend>
	</fieldset>

	<form class="layui-form" id="myform">
		<!-- <input type="hidden" id="proId" name="proId"> -->
		<div class="layui-form-item">
			<label class="layui-form-label">企业名称</label>
			<div class="layui-input-block">
				<input type="text" name="entName" id="entName" lay-verify="required"
					placeholder="请输入" autocomplete="off" class="layui-input"
					maxlength="10">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">生产地区</label>
			<div class="layui-input-block">
				<select name="preId" id="preId" autocomplete="off"
					class="layui-input" lay-verify="required">
					<option></option>
				</select>
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">开始日期</label>
			<div class="layui-input-inline">
				<input type="text" name="startTime" id="startTime" lay-verify="date"
					placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
			</div>
			<label class="layui-form-label">完成日期</label>
			<div class="layui-input-inline">
				<input type="text" name="endTime" id="endTime" lay-verify="date"
					placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
			</div>
		</div>
		<div class="layui-form-item layui-form-text">
			<label class="layui-form-label">生产许可</label>
			<div class="layui-input-block">
				<textarea id="proScope" name="proScope" placeholder="请输入内容"
					class="layui-textarea" lay-verify="required" maxlength="240"></textarea>
			</div>
		</div>
		<!-- 提交重置 -->
		<div class="layui-form-item">
			<div class="layui-input-block">
				<input type="button" class="layui-btn" lay-filter="productionAdd"
					value="立即提交" id="submit">
				<button type="reset" class="layui-btn layui-btn-primary">重置</button>
			</div>
		</div>
	</form>

	<script src="../../layui/layui.js"></script>
	<script type="text/javascript"
		src="../../res/wzw/js/jquery.min.1.6.4.js"></script>
	<script src="../../res/wzw/js/jquery-1.10.2.js"></script>

	<script>
	layui.use(['form', 'layer','laydate'], function(){
	  var form = layui.form
	  ,layer = layui.layer
	  ,laydate = layui.laydate
	  ,$ = layui.$;
	  
	  //日期
	  laydate.render({
	    elem: '#startTime'
	  });
	  laydate.render({
	    elem: '#endTime'
	  });
	  
	  form.on('submit(productionAdd)',function(){
		  parent.location.reload(); // 父页面刷新
	  }); 
	  
	  var url = "../../pre/findAlls.action";
		$.post(url,null,function(data){
			for(var i=0;i<data.length;i++){
				$("#preId").append("<option value="+data[i].preId+">"+data[i].preSite+"</option>");
			}
			//form表单重新渲染
			form.render();
		},dataType="JSON");
		
		$("#submit").on('click',function(){
			alert(123);
			var fromJson = $("#myform").serializeArray();
			alert(JSON.stringify(fromJson));
			alert(fromJson[0].value);
			if(fromJson[0].value != "" && fromJson[1].value != "" && fromJson[2].value != '' && fromJson[3].value != '' && fromJson[4].value != ''){
				var data = {"entName":fromJson[0].value,"preId":fromJson[1].value,"startTime":fromJson[2].value,"endTime":fromJson[3].value,"proScope":fromJson[4].value};
				var url = "../../SalesStatistics/addProduction.action";
				$.ajax({
					url:url,
					data:data,
					success:function(msg){
						alert(msg.rows);
						var rows = msg.rows;
						if(rows > 0){
							sessionStorage['numOne'] = msg.proId;
							layer.msg('添加成功!',{time:1000},function(){
								parent.location.reload();
							});
						}else {
							sessionStorage['numOne'] = "";
							layer.msg('添加失败!',{time:1000},function(){
								parent.location.reload();
							});
						}
					},
					dataType:"JSON"
				});
			}else {
				layer.msg('请完善信息',{time:1000});
			}
		})
	});
	
</script>

</body>
</html>